package com.qymerge.manage.base.service.impl;

import com.qymerge.manage.base.dao.IMetaProfitReportItemDao;
import com.qymerge.manage.base.dao.IMetaProfitReportItemDetail2Dao;
import com.qymerge.manage.base.ro.MetaProfitReportItemDetail2RO;
import com.qymerge.manage.base.service.IMetaProfitReportItemDetail2Service;
import com.qymerge.manage.core.bean.ActionResultRO;
import com.qymerge.manage.core.bean.DataTableRO;
import com.qymerge.manage.core.bean.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>Title: MetaProfitReportItemDetail2ServiceImpl</p>
 * <p>Description: 报表项目与科目的关系</p>
 *
 * @author Xiao
 * @date 2025/4/29 18:43
 * @version 1.0.0
 */
@Service
public class MetaProfitReportItemDetail2ServiceImpl implements IMetaProfitReportItemDetail2Service {

    @Autowired
    private IMetaProfitReportItemDetail2Dao metaProfitReportItemDetail2Dao;
    @Autowired
    private IMetaProfitReportItemDao metaProfitReportItemDao;

    /**
     * 查询
     *
     * @param ro
     * @param pageRequest
     * @return
     */
    @Override
    public DataTableRO list(MetaProfitReportItemDetail2RO ro, PageRequest pageRequest) {
        List<MetaProfitReportItemDetail2RO> list = metaProfitReportItemDetail2Dao.list(ro, pageRequest);
        DataTableRO dataTableRO = new DataTableRO();
        int allCount = metaProfitReportItemDetail2Dao.total(ro);
        int pageSize = pageRequest.getSize();
        dataTableRO.setAll_count(allCount);
        dataTableRO.setList(list);
        dataTableRO.setCurrent_page(pageRequest.getPage());
        dataTableRO.setPage_size(pageSize);
        int allPage = (allCount % pageSize == 0 ? allCount / pageSize : allCount / pageSize + 1);
        dataTableRO.setAll_page(allPage);
        return dataTableRO;
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public MetaProfitReportItemDetail2RO detail(Long id) {
        MetaProfitReportItemDetail2RO metaProfitReportItemDetail2DaoOne = metaProfitReportItemDetail2Dao.findOne(id);
        return metaProfitReportItemDetail2DaoOne;
    }

    @Override
    public ActionResultRO save(MetaProfitReportItemDetail2RO ro) {
        int rn = metaProfitReportItemDetail2Dao.insert(ro);
        return new ActionResultRO(rn, ro.getId() == 0 ? "保存成功" : "保存失败");
    }

    @Override
    public ActionResultRO delete(Long[] ids) {
        int rn = metaProfitReportItemDetail2Dao.remove(Arrays.asList(ids));
        return new ActionResultRO(true, "删除" + rn +"成功", "删除" + rn +"失败");
    }


}
